DEFINE CLASS cl_talonario as Custom

id_talonario=0
descripcion=""
	
PROCEDURE getid_talonario
RETURN this.id_talonario
ENDPROC

PROCEDURE setid_talonario
LPARAMETERS nuevo
this.id_talonario=nuevo
ENDPROC

PROCEDURE getdescripcion
RETURN this.descripcion
ENDPROC

PROCEDURE setdescripcion
LPARAMETERS nuevo
this.descripcion=nuevo
ENDPROC

PROCEDURE nuevo_talonario
USE DATA1/talonario
INSERT INTO talonario(descripcion, nro_comprobante) VALUES (this.descripcion, 1)
SELECT MAX(id_talonario)id FROM talonario into CURSOR cursorID
nuevoID=cursorID.id
USE IN talonario
USE IN cursorID
ENDPROC
	
PROCEDURE buscar_talonario
LPARAMETERS id
USE DATA1/talonario
SELECT * FROM talonario WHERE id_talonario=id INTO CURSOR cat
IF _tally==0 then
USE IN cat
USE IN talonario
RETURN .f.
ELSE
this.descripcion=cat.descripcion
ENDIF
USE IN talonario	
USE IN cat
ENDPROC
	
PROCEDURE borrar
SET DELETED on
USE DATA1/talonario
DELETE FROM talonario WHERE id_talonario=this.id_talonario
USE IN talonario
ENDPROC
	
PROCEDURE modificar
USE DATA1/talonario
UPDATE  talonario set descripcion=this.descripcion WHERE id_talonario=this.id_talonario
USE IN talonario
ENDPROC		

PROCEDURE cargaTalonarios
USE DATA1/talonario
SELECT * FROM talonario INTO CURSOR cur_talonarios
LOCAL xml_talonarios
CURSORTOXML("cur_talonarios","xml_talonarios",1,48)
USE IN talonario
RETURN xml_talonarios

PROCEDURE obtieneUltNroComprobante
LPARAMETERS param_talonario
USE DATA1/talonario
SELECT nro_comprobante FROM talonario WHERE id_talonario=param_talonario INTO cursor cur_nro
ultNro=cur_nro.nro_comprobante
USE IN talonario
USE IN cur_nro
RETURN ultNro
ENDPROC 

PROCEDURE incrementaNroComprobante
LPARAMETERS talonarioUsado
USE data1/talonario
UPDATE talonario SET nro_comprobante=nro_comprobante+1 WHERE id_talonario=talonarioUsado
USE IN talonario
ENDPROC

ENDDEFINE